const app = getApp()
Component({
  data: {
    isShowModal:false,
    indexAc: 0,
    list: [{
        id: 0,
        name: '首页',
        icon: '/static/iconfont/shouye.png',
        activeIcon: '/static/iconfont/shouye1.png',
        urls:'/pages/index/index'
      },
      {
        id: 1,
        name: '电话咨询',
        icon: '/static/iconfont/dianhua.png',
        activeIcon: '/static/iconfont/dianhua1.png'
      },
      {
        id: 2,
        name: '企业抖音',
        icon: '/static/iconfont/brand_tiktok.png',
        activeIcon: '/static/iconfont/brand_tiktok1.png'
      },
      {
        id: 3,
        name: '联系我们',
        icon: '/static/iconfont/weibiaoti-3.png',
        activeIcon: '/static/iconfont/weibiaoti-31.png',
        urls:'/pages/aboutus/aboutus'
      },
    ],
    form:{}
  },
  properties: {
    acitveAc: {
      type: Number
    }
  },
  ready() {
    this.setData({
      indexAc: this.properties.acitveAc
    })
  },
  attached() {
    this.getDetails()
    // if(this.data.form){
    //   setTimeout(()=>{
    //     this.setData({
    //       form:app.globalData.siteInfo
    //     })
    //   },200)
    // }
  },
  methods: {
    getDetails() {
      app.getRequest('/applet/site/detail', 'GET', '').then(res => {
        if (res.code == 200) {
          res.data.siteInfo.coverUrl = app.globalData.serverUrl + res.data.siteInfo.coverUrl
          res.data.siteInfo.logoUrl = app.globalData.serverUrl + res.data.siteInfo.logoUrl
          res.data.siteInfo.wechatQrUrl = app.globalData.serverUrl + res.data.siteInfo.wechatQrUrl
          this.setData({
            form: res.data.siteInfo
          })
        }
      })
    },
    tabHeld(e) {
      let that = this
      let valueIndex = e.currentTarget.dataset.index
      if (valueIndex == 1) {
        tt.makePhoneCall({
          phoneNumber: that.data.form.contact,
          success(res) {
            console.log("调用成功", res.errMsg);
          },
          fail(res) {
            tt.showToast({
              title: res.errMsg,
              icon:'none'
            });
          },
        })
      } else if(valueIndex==2){
       that.setData({
        isShowModal:true
       })
      }
      else {
        that.setData({
          indexAc: valueIndex
        })
        tt.setStorageSync('indexAC', valueIndex);
        this.triggerEvent("navtab", valueIndex)
      }
    },
    hideModal(){
      this.setData({
        isShowModal:false
       })
    },
    copyInfo(e){
      tt.setClipboardData({
        data:e.currentTarget.dataset.info
      })
    },
  }
})